<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends CommonAction {

    /**
     * 首页
     */
    public function index(){
          $user = $this->getUser();
          $data = D('article')->articListByPage($_GET);
          $this->data = $data;
          $this->user = $user;
          $this->display("index");
    }

    public function showArt(){
          $user = $this->getUser();
          $data = D('article')->getArticleByOne(array('id'=>$_GET['id']));
          // 处理查看数据
          $data = D('article')->processData($data);
          // 得到相关文章
          $relationData = D('article')->getRelationByKeyWord($data['title']);
          // 获取评论数据
          $comment = D("article")->getComment($data['id']);
          // 喜欢数据
          $like = D("MemberFavor")->getfavorByOne(array('pid'=>$_GET['id'],'uid'=>session('uid')));
          if($like){
                $like['isLike'] = 1;
                $this->like =  $like;
          }
          $this->rdata = $relationData;
          $this->data = $data;
          $this->comment = $comment;

          $this->display('zhengwen');
    }

    /**
     * 添加评论
     */
    public function addComment(){

        $res = D("Comment")->CommentAdd($_POST);
        echo json_encode($res);

    }

    /**
     *  添加回复
     */
    public function addCommentReply(){
        $res = D("Comment")->CommentAdd($_POST,1);
        echo json_encode($res);
    }

    /**
     * 创建喜欢的分类
     */
    public function addUserFavorClass(){
         $res = D("MemberFavorClass")->addFavorClass($_POST);
         echo json_encode($res);
    }

    /**
     * 获取我的分类
     */
    public function getFavorClassList(){

          $FavorClass = D("MemberFavorClass")->getFavorClassList($_POST);
          echo json_encode($FavorClass);
    }

    /**
     * 添加喜欢
     */
    public function addLike(){
          $res = D("MemberFavor")->addFovar($_POST);
          echo json_encode($res);
    }

    /**
     * 懒加载评论
     */
    public function getLazyCommonList(){
          $common = D("Comment")->getCommentList($_GET['id'],1,$_GET['page']);
          echo json_encode($common);
    }

    /**
     * 删除喜欢
     */
    public function ramoveLike(){
        $res = D("MemberFavor")->removeFavor($_POST);
        echo json_encode($res);
    }
}